package {{.table}}

import (
	"sync"
	"time"
	"xian-server/lib/database"
)

type {{.schema.Opts.UpperCamelCaseTable}}Id string

type {{.schema.Opts.UpperCamelCaseTable}} struct {
	Id string `db:"id"`
	{{range .schema.Columns}}
	// {{.ColumnComment}}
  {{.SrcProps}} {{.SrcType}} `db:"{{.ColumnName}}"`
	{{end}}
}

func (m {{.schema.Opts.UpperCamelCaseTable}}) Table() string {
	return "{{.schema.Opts.FullTableName}}"
}

func (m {{.schema.Opts.UpperCamelCaseTable}}) INew() database.IModel {
	return m.New()
}

func (m {{.schema.Opts.UpperCamelCaseTable}}) GetId() string {
	return m.Id
}

func (m {{.schema.Opts.UpperCamelCaseTable}}) Database() string {
	return ""
}

func (m {{.schema.Opts.UpperCamelCaseTable}}) New() *{{.schema.Opts.UpperCamelCaseTable}} {
	return &{{.schema.Opts.UpperCamelCaseTable}}{}
}

func (m {{.schema.Opts.UpperCamelCaseTable}}) NewSplice() *[]{{.schema.Opts.UpperCamelCaseTable}} {
	return &[]{{.schema.Opts.UpperCamelCaseTable}}{}
}

var (
	instance{{.schema.Opts.UpperCamelCaseTable}}Model *{{.schema.Opts.UpperCamelCaseTable}}
	once{{.schema.Opts.UpperCamelCaseTable}}Model     sync.Once
)

func New{{.schema.Opts.UpperCamelCaseTable}}Model() *{{.schema.Opts.UpperCamelCaseTable}} {
	once{{.schema.Opts.UpperCamelCaseTable}}Model.Do(func() {
		instance{{.schema.Opts.UpperCamelCaseTable}}Model = &{{.schema.Opts.UpperCamelCaseTable}}{}
	})
	return instance{{.schema.Opts.UpperCamelCaseTable}}Model
}
